import java.util.Arrays;

public class Learn15 {
    public static void swap(int[] array,int x,int y){
     int tmp = array[x];
     array[x] =array[y];
     array[y] = tmp;
    }

    public static void func(int[] array){
     int left = 0;
     int right = array.length-1;
     while(left < right){

         while(left < right && array[left] % 2 != 0){      //不要忘了是 array[left] 不是 left
             left++;
         }

         while(left < right && array[right] % 2 == 0){
             right--;
         }

         swap(array,left,right);
     }
    }

    public static void sortOda(int[] array){
        for (int i = 0; i < array.length-1; i++) {
            boolean flg = true;
            for (int j = 0; j < array.length-i-1;j++){
                if(array[j] % 2 == 0){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = false;
                }
            }
            if(flg == true){
                break;
            }
        }
    }


    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6};
        //sortOda(array);           //冒泡排序实现，奇数位于偶数之前
        func(array);
//        System.out.println(Arrays.toString(array));
        for (int x:array) {
            System.out.print(x +" ");
        }
    }
}
